package com.lwt.dao.base.dao.daoImpl;

import com.lwt.dao.base.BaseDao;
import com.lwt.dao.base.dao.StudentDao;
import com.lwt.pojo.Student;

import java.util.List;

/**
 * @Author Li Weitong
 * @Date 2020/11/22 11:49
 */
public class StudentDaoImpl extends BaseDao implements StudentDao {
    @Override
    public int addStudentInfo(Student student) {
        String sql = "insert into sm_student values(?,?,?,?)";
        return update(sql,student.getStudentId(),student.getStudentName(),student.getGender(),student.getGradeId());
    }

    @Override
    public int deleteStudentById(Integer studentId) {
        String sql = "delete sm_student where studentId=?";
        return update(sql,studentId);
    }

    @Override
    public int updateStudent(Student student) {
        String sql = "update sm_student set studentId=?,studentName=?,gender=?,gradeId=? where studentId=?";
        return update(sql,student.getStudentId(),student.getStudentName(),student.getGender(),student.getGradeId(),student.getStudentId());
    }

    @Override
    public Student queryStudentById(Integer studentId) {
        String sql = "select studentId,studentName,gender,gradeId from sm_student where studentId=?";
        return queryForOne(Student.class,sql,studentId);
    }

    @Override
    public Student queryStudentByName(String studentName) {
        String sql = "select studentId,studentName,gender,gradeId from sm_student where studentName=?";
        return queryForOne(Student.class,sql,studentName);
    }

    @Override
    public List<Student> queryStudentByGradeId(Integer gradeId) {
        String sql = "select studentId,studentName,gender,gradeId from sm_student where gradeId=?";
        return queryForList(Student.class,sql,gradeId);
    }

    @Override
    public List<Student> queryStudentList() {
        String sql = "select studentId,studentName,gender,gradeId from sm_student";
        return queryForList(Student.class,sql);
    }
}
